package com.zxl.live.screen.screen.ui.widget.panel.heart;

import android.graphics.Canvas;
import android.graphics.Paint;

import java.util.ArrayList;
import java.util.List;

public class Bloom {
	
	public Vector p;

	public float r;

	public int c;

	public float pc;

	public Garden garden;

	public List<Petal> petals;

	public Bloom(Vector p, float r, int c, float pc, Garden garden) {
		this.p = p;
		this.r = r;
		this.c = c;
		this.pc = pc;
		this.garden = garden;
		petals = new ArrayList<Petal>();
		init();
		this.garden.add(this);
	}
	
	public void init() {
		float angle = 360f / this.pc;
		int startAngle = Garden.randomInt(0, 90);
		for (int i = 0; i < this.pc; i++) {
			this.petals.add(
					new Petal(
							Garden.random(Garden.PETALSTRETCH_MIN, Garden.PETALSTRETCH_MAX), 
							Garden.random(Garden.PETALSTRETCH_MIN, Garden.PETALSTRETCH_MAX), 
							startAngle + i * angle, 
							angle, 
							Garden.random(Garden.GROWFACTOR_MIN, Garden.GROWFACTOR_MAX), this));
		}
	}
	
	public void draw(Canvas canvas, Paint paint, int alpha) {
		Petal p;
		canvas.save();
		canvas.translate(this.p.x, this.p.y);
		for (int i = 0; i < petals.size(); i++) {
			p = petals.get(i);
			paint.setColor(c);
			p.render(canvas, paint, alpha);
		}
		canvas.restore();
	}
}
